<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>行政管理--会议室管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" href="css/wangyachong/wangyachong.css" type="text/css"></link>
  <link rel="stylesheet" href="easyui/themes/icon.css" type="text/css"></link>
  <link rel="stylesheet" href="easyui/themes/default/easyui.css" type="text/css"></link>
  <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
  <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
  
  <script type="text/javascript">
  var dname;
  	$(function(){	 	  				  	  			
  				$.post("users/findById.do","id="+$("#add-createid").val(),function(data){
  	  					  	dname= data.name; 		
  	  					  	init();		
  	  			},"json");
  	  			
  	  			$.post("dept/findById.do","id="+$("#deptId").val(),function(data){
	  				$("#deptmanagerid").val(data.deptmanagerid);	  	  				  	  			
  				$.post("users/findById.do","id="+$("#deptmanagerid").val(),function(data){
  	  				$("#deptmanagername").val(data.name);	  	  				
  	  			},"json");
				},"json");
	
  	});
 
  	
  	//会议室管理
  		//表格填充
  		function init(){
  		$("#dg").datagrid({
  			url:"meetingroom/findAll.do",
  			striped:true,	  			
  			rownumbers:true,
  			pagination:true,
  			pageList:[10,20,50],
  			columns:[[{
  				title:"会议室名称",
  				field:"name",
  				width:100,
  				align:"right",
  			},{
  				title:"会议室描述",
  				field:"description",
  				width:100,
  				align:"right",
  			},{
  				title:"操作",
  				field:"id",
  				width:100,
  				align:"right",
  				//把当前行内容替换成 return的内容
  				formatter:function (value,row,index){
					return "<a onclick='update("+row.id+")' href='javascript:void(0)'>修改</a>&nbsp;&nbsp;<a onclick='del("+row.id+")' href='javascript:void(0)'>删除</a>";
					}
				}
  			]],
  			toolbar:[{text:"新增",iconCls:"icon-add",handler:function(){
	  				add();
	  			}}]	
  		});
  		$("#dlg").dialog({
  			title:"添加会议室",
  			width:400,
  			heigh:300,
  			closed:true,
  			buttons:[{
  				text:"添加",
  				handler:function(){
  					var data="name="+$("#name").val()+
  							 "&description="+$("#description1").val();
  					//ajax提交
  				
  					$.get("meetingroom/add.do",
  						  data,
  						  function(data){
  						  	alert(data);
  						  	$("#dlg").dialog("close");
							$("#dg").datagrid("reload");
  						  },
  						  "text"		
	  					);
  				}
  			},{
  				text:"取消",
  				handler:function(){
					$("#dlg").dialog("close");
				}
  			
  			}]
  		});
  		
  		
 		$("#update").dialog({
			title:"修改会议室",
			width:400,
			heigh:300,
			closed:true,
			buttons:[{
				text:"修改",
				handler:function(){
					var data="id="+$("#u-id").val()+"&name="+$("#u-name").val()+
							 "&description="+$("#u-description").val();
					//ajax提交
					$.get("meetingroom/update.do",
						  data,
						  function(data){
						  	alert(data);
						  	$("#update").dialog("close");
							$("#dg").datagrid("reload");
						  },
						  "text");
				}
	  		},{
	  			text:"取消",
	  			handler:function(){
					$("#update").dialog("close");
				}
	  			
	  		}]
	  	});
	  	
	  	
		//会议室预定
  		$("#search").click(function(){
  			$("#add-begindate").val($("#beginDate").val());
			$("#add-enddate").val($("#endDate").val());
			$("#reserve_table").datagrid({	  		
	  			url:"meetingroom/findByParam.do?begindate="+$("#beginDate").val()
	  					+"&enddate="+$("#endDate").val()+"&description="+$("#description").val(),
	  			striped:true,	  			
	  			rownumbers:true,
	  			singleSelect:true,
	  			columns:[[{
	  				checkbox:true
	  			},{
	  				title:"会议室名称",
	  				field:"name",
	  				width:300,
	  				align:"right",
	  			},{
	  				title:"类型",
	  				field:"description",
	  				width:300,
	  				align:"center"
	  			
	  			}
					]],
					onSelect:function(index,rows){
					
			  				$.post("meetingroomorder/findById.do","id="+rows.id,function(data){
			  	  				$("#add-meetingroomid").val(data.id);
			  	  				$("#add-name").val(data.name);
			  	  				$("#add-description").val(1);
			  	  				
			  	  			},"json");
			  	  			
			  	  				/*查询经理的id*/
				     		$.post("dept/findById.do","id="+$("#deptid").val(),function(data){
					  				$("#deptmanagerid").val(data.deptmanagerid);	  	  				  	  			
				  				$.post("users/findById.do","id="+$("#deptmanagerid").val(),function(data){
				  	  				$("#deptmanagername").val(data.name);	  	  				
				  	  			},"json");
								},"json");
								}
	  		});
		});
		
		//会议室预定管理
		$("#manager_table").datagrid({
				url:"meetingroomorder/findAll.do",
	  			striped:true,	  			
	  			rownumbers:true,
	  			singleSelect:true,
	  			columns:[[{
	  				title:"会议室编号",
	  				field:"meetingroomid",
	  				width:70,
	  				align:"center",
	  			},{
	  				title:"开始时间",
	  				field:"begindate",
	  				width:70,
	  				align:"center",
	  				formatter:date
	  			},{
	  				title:"结束时间",
	  				field:"enddate",
	  				width:70,
	  				align:"center",
	  				formatter:date
	  			},{
	  				title:"会议室类型",
	  				field:"wordid",
	  				width:70,
	  				align:"center",
	  			},{
	  				title:"创建时间",
	  				field:"ordertime",
	  				width:70,
	  				align:"center",
	  				formatter:date
	  			},{
	  				title:"申请人",
	  				field:"createid",
	  				width:70,
	  				align:"center",
	  				formatter:function (value){
          					return dname;
          					 
    	  				}
	  			},{
	  				title:"操作",
	  				field:"id",
	  				width:70,
	  				align:"center",
	  				//把当前行内容替换成 return的内容
  					formatter:function (value,row,index){
						return "<a onclick='manager("+row.id+")' href='javascript:void(0)'>取消预订</a>";
					}
	  			}]]
		});
		
		
		
		
		//function括号	
  	};
  	


	function manager(value){
		$.messager.confirm("提示框","确定要删除吗？",
				function(r){
					if(r){
						var data="id="+value;
						$.post(
							"meetingroomorder/delete.do",data,
							function(data){
								$("#manager_table").datagrid("reload");
							},
							"text"
						);
					}			
				}
		);
	
	}










//会议室管理
  	//弹出框开启
  	function add(){
	  	$("#dlg").dialog("open");
	}; 
	//弹出修改框
	function update(value){
		$("#update").dialog("open");
	
		$.post("meetingroom/findById.do","id="+value,
				function(data){
					$("#u-id").val(value);
					$("#u-name").val(data.name);
					$("#u-description").val(data.description);
				},"json");
	}
	function del(value){
		$.messager.confirm("提示框","确定要删除吗？",
				function(r){
					if(r){
						var data="id="+value;
						$.post(
							"meetingroom/delete.do",data,
							function(data){
								alert(data);
								$("#dg").datagrid("reload");
							},
							"text"
						);
					}			
				}
		);
	}
	function date(value){
		return value.year+1900+"-"
		+(value.month+1)+"-"+value.date;
		};
	
	
	
  </script>
   <c:if test="${message!=null }">
	<script>
		alert('${message}');
	</script>
 </c:if>
  </head>
  
  <body>
    <div id="mainbody">
    	<p><img src="css/wangyachong/img/icons/contacts.png" width="32px" height="32px"/>&nbsp;&nbsp;<span>行政管理</span></p>
	    <div class="title"> 会议室管理</div>
	    
	    <div class="easyui-tabs">
	        
	    	<div id="meeting_apply" title="会议室预定">
	    	
	   			
	
		   		<table id="reserve_table"></table>
			
			
				<!-- 查出的预定信息回填 -->
				<div class="content">
				<div>
	   				<table><tr><td>
	   				预定时间段: 
	   				<input type="text" id="beginDate" name="begindate" />
					to
					<input type="text" id="endDate" name="enddate"/>
					<input type="button" value="查询" id="search" class="button">
	   				<span>会议室类型：
							<select name="description" id="description">
								<option value="">请选择会议类型</option>
								<option value="1">会议</option>
								<option value="2">培训</option>
								<option value="3">面试</option>	
								<option value="4">会客</option>	
								<option value="5">其他</option>						
							</select>
						</span>
	   				</td></tr></table>
	   			
			    		
					</div>
			   		<form method="post" action="meetingroomorder/add.do" id="myform" >
				    	<table cellpadding="0" cellspacing="0">
				    	
				    		<tr>
				    			<td>会议室名称：</td>
				    			<td>
									<input class="input-text" type="text" id="add-name" name="name" value=""  readonly="readonly"/>
				    				<input class="input-text" type="hidden" id="add-meetingroomid" name="meetingroomid" value="" />
				    				<!-- wordid  直接存描述 -->
									<input class="input-text" type="hidden" id="add-description" name="wordid" value="" readonly="readonly" />
				    			</td>	
				    		</tr>
				    		
				    				
				    		
				    		
				    		<tr>
				    			<td>部门名称：</td>
				    			<td>
									<input class="input-text" type="text" id="deptname" name=deptname value="${user.deptname}" readonly="readonly"/>
									<input class="input-text" type="hidden" id="deptid" name=deptid value="${user.deptid}" />
				    			</td>	
				    		</tr>
				    		<tr>
				    			<td>开始时间：</td>
				    			<td>
									<input class="input-text" type="text" id="add-begindate" name="begindate" value="" readonly="readonly"/>
									
				    			</td>	
				    		</tr>
				    		<tr>
				    			<td>结束时间：</td>
				    			<td>
									<input class="input-text" type="text" id="add-enddate" name="enddate" value="" readonly="readonly"/>
				    			</td>	
				    		</tr>
				    		<tr>
				    			<td>申请人：</td>
				    			<!-- createid   创建人id -->
				    			<td><input class="input-text" type="text" id="user-name" name="user-name" value="${user.name}" readonly="readonly">
				    			<input class="input-text" type="hidden" id="add-createid" name="createid" value="${user.id}"></input>
									
				    			</td>	
				    		</tr>
				    		<tr>
				    			<td>下一步审批人：</td>
				    			<td><input class="input-text" type="hidden" id="deptId" name="deptId" value="${user.deptid}" />
									<input class="input-text" type="hidden" id="deptmanagerid" name="deptmanagerid" value=""/>
									<input class="input-text" type="text" id="deptmanagername" name="deptmanagername" value="" readonly="readonly"/>
				    			</td>	
				    		</tr>
				    		
			    		</table>
			    		<input class="button" type="submit" id="submit" name="submit" value="确定" />
			    		<input class="button" type="reset" id="reset" name="reset" value="取消" />
			    	</form>
			    	</div>		   				
	      </div>
	     
	      
	      <div id="meeting_reservemanager"  title="会议室预定管理">
		      <div id="manager_div">
		     	 <table id="manager_table"></table>
		      
		      
		      
		      </div>
	      		
	      	
	      </div>
	      <c:if test="${user.deptid=='1'or user.roleid=='5'  }">
	        <div id="meeting_meetroommanager" title="会议室管理">
	  		
	  		<table id="dg"></table>
	    	<table id="dlg">
	    		<tr>
	    			<td>会议室名称</td>
	    			<td>
	    				<input type="text" id="name"/>
	    			</td>
	    		</tr>
	    		<tr>
	    			<td>会议室描述</td>
	    			<td>
	    				<input type="text" id="description1"/>
	    			</td>
	    		</tr>
	    	</table>
	    	<table id="update">
	    		<tr>
	    			<td>会议室名称</td>
	    			<td>
	    				<input type="hidden" id="u-id" />
	    				<input type="text" id="u-name"/>
	    			</td>
	    		</tr>
	    		<tr>
	    			<td>会议室描述</td>
	    			<td>
	    				<input type="text" id="u-description"/>
	    			</td>
	    		</tr>
	    	</table>
	      </div>
	       </c:if>
        </div>
     
    </div>
  </body>
</html>
